import {defineStore} from 'pinia'

interface stateCountType {
    count:number
}

const useCountStore = defineStore('count',{
    state:():stateCountType=>{
        return {
            count:1
        }
    },
    getters:{
        doubleCount:(state):number=>{
            return state.count * 2
        }
    },
    actions:{
        // 累加
        increment(){
            this.count++
        },
        // 累加 n
        incrementN(n:number){
            this.count+=n
        },
        // 异步累加 n
        asyncIncrementN(n:number){
            setTimeout(()=>{
                this.count+=n
            },2000)
        }
    }
})
export default useCountStore